
 var permissionState=config.permissionState;
 var role=getSessionStorage("role");

 if(permissionState==1){
     //未授权
     var btn="<button class=\"btn\" id='askAuthorization' title=\"点击向管理员发起授权请求\" >点击请求授权</button>";
     $("#targetArea").html(btn);
 }else if(permissionState==0){
     //已请求授权
     var btn="<button class=\"enbtn\" title=\"已向管理员发起授权请求\" onclick=\"alert('请勿重复请求授权')\" disabled >已请求授权</button>";
     $("#targetArea").html(btn);
 }else if(permissionState==2){
     //检测到已经授权
     if(permissionState==2||permissionState=="2"){
         var loc;//跳转页面地址

         if (role==="operator"){
             loc="index.html";
         }
         else if (role==="auditor"){
             loc="auditor.html";
         }
         else if (role==="sysAuditor"){
             loc="systemAuditor.html";
         }
         else if (role==="admin"){
             loc="admin.html";
         }
         location.href=loc+"?token="+config.token;
     }
 }

//请求授权
function askAuthorization() {
    $.ajax({
        url:HOST.concat("/askauthorized?token="+config.token),
        type:"POST",
        data:{"username":getSessionStorage("username")},
        async:false,
        dataType:"json",
        success:function(res){
            if(res.meta.state=="success"){
                console.log(res);
                alert(res.meta.message);
                var btn="<button class=\"enbtn\" title=\"已向管理员发起授权请求\" onclick=\"alert('请勿重复请求授权')\" disabled >已请求授权</button>";
                $("#targetArea").html(btn);

            }
        }
    });
}


$("#askAuthorization").live("click",function () {
    askAuthorization();
});
